﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;

namespace VipSoft.Core.Utility
{
    public static class ConvertHandler
    {
        public static int ToInt32(object value)
        {
            var num = 0;
            if (value is int)
            {
                num = Convert.ToInt32(value);
            }
            return num;
        }

        public static string ToString(int[] values)
        {
            var result = new StringBuilder();
            var count = values.Length;
            if (count > 1)
            {

                for (var i = 0; i < count; i++) result.AppendFormat("{0},", values[i]);
            }
            else
            {
                result.Append(values[0]);
            }
            return result.ToString().TrimEnd(',');
        }

        /// <summary>
        /// 钱币转换成大写
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public static string ToChinese(decimal x)
        {
            var s = x.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");
            var d = Regex.Replace(s, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}");
            return Regex.Replace(d, ".", m => "负圆空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟萬億兆京垓秭穰"[m.Value[0] - '-'].ToString(CultureInfo.InvariantCulture));
        }
    }
}
